import { getUserinfoApi } from '@/api';
import { UserType } from '@/types';
import Taro from '@tarojs/taro';
import { toast } from '.';

export const getUser = (): UserType => Taro.getStorageSync('user');
export const setUser = data => Taro.setStorage({ key: 'user', data });

export const getToken = () => Taro.getStorageSync('token');
export const setToken = data => Taro.setStorage({ key: 'token', data });

export function reloadUserInfo() {
  getUserinfoApi(getUser().kid)
    .then(res => {
      setUser(res);
    })
    .catch(() => toast('获取个人信息失败'));
}
